<!-- 右 -->
<div class="content">
    <div class="header">
        <h1 class="page-title">分派权限</h1>
    </div>

    <div class="well">
        正在给【{$role.role_name}】分派权限
        <form action="{:url('saveauth')}" method="post">
            <input type="hidden" name="role_id" value="{$role.id}">
            <!-- table -->
            <table class="table table-bordered table-hover table-condensed">
                <thead>
                    <tr>
                        <th>权限分类</th>
                        <th>权限</th>
                    </tr>
                </thead>
                <tbody>
                    {foreach $top_auth as $top_v}
                    <tr class="success">
                        <td><input type="checkbox" class="top_auth" name="id[]" value="{$top_v.id}" {in name='top_v.id'
                                value='$role.role_auth_ids' }checked="checked" {/in}>{$top_v.auth_name} </td> <td>
                            {foreach $second_auth as $second_v}
                            {if ($top_v.id == $second_v.pid)}
                            <input type="checkbox" class="second_auth" name="id[]" value="{$second_v.id}" {in name='second_v.id'
                                value='$role.role_auth_ids' }checked="checked" {/in}>{$second_v.auth_name} {/if} {/foreach}
                                </td> </tr> {/foreach} </tbody> </table> <button class="btn btn-primary" type="submit">保存</button>
        </form>
    </div>
    <script>
        $(function () {
            /* 
                表单全选
             */
            $('.top_auth').change(function () {
                var status = $(this).prop('checked');
                $(this).closest('tr').find('.second_auth').prop('checked', status);
            })
            $('.second_auth').change(function () {
                $checked = $(this).closest('td').find('.second_auth:checked');
                var status = $checked.length > 0;
                $(this).closest('tr').find('.top_auth').prop('checked', status);
            })
        })
    </script>